/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * This file is part of retabel.
 *
 * Copyright (c) 2011 by individual contributors as indicated by the
 * @author tags. See the copyright.txt file in the distribution
 * for a full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

package org.retabel.persistence.dao.document;

import org.retabel.persistence.dao.AbstractEntityDaoBean;
import org.retabel.persistence.entity.document.ExportConfiguration;

import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 * Class description.
 * <p/>
 * <h3>Extra-Info</h3>
 * Created: 16:36 12.08.11
 *
 * @author Burt Parkers
 * @version 1.0
 */
@Stateless
@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public class ExportConfigurationDaoBean extends AbstractEntityDaoBean<ExportConfiguration> implements ExportConfigurationDao {

    /** The EntityManager. */
    @PersistenceContext(unitName = "retabel-persistence")
    private EntityManager entityManager;


    public ExportConfigurationDaoBean() {
        super(ExportConfiguration.class);
    }

    @Override
    protected EntityManager getEntityManager() {
        return entityManager;
    }

    @Override
    public ExportConfiguration findByName(String name) {
        try {
            Query query = entityManager.createNamedQuery("ExportConfiguration.findByName");
            query.setParameter(1, name);
            return (ExportConfiguration) query.getSingleResult();
        } catch (NoResultException e) {
            return null;
        }
    }

}
